package unit;

import java.util.Enumeration;

import junit.framework.Test;
import junit.framework.TestFailure;
import junit.framework.TestResult;
import junit.framework.TestSuite;

public class Tester {

	protected static final Object[][] TESTS = new Object[][] {
		{ "io.Ascii",										unit.UAscii.class },
		{ "util.ByteUtils",									unit.UByteUtils.class },
		{ "aprs.LatOrLong",	unit.ULatOrLong.class },
		{ "aprs.AprsPacketData",	unit.UAprsPacketData.class },
		{ "aprs.AprsFormatter",	unit.UAprsFormatter.class },
		{ "aprs.AprsPacketDataObject",	unit.UAprsPacketDataObject.class },
		{ "xastir.ObjectXmitter",	unit.UObjectXmitter.class },
		{ "util.StationCallCollator",	unit.UStationCallCollator.class },
		{ "util.StationCallSuffixCollator",	unit.UStationCallSuffixCollator.class },
		{ "io.StationDbReader",	unit.UStationDbReader.class },
		{ "io.StationDbWriter",	unit.UStationDbWriter.class },
		//{ "io.ByteSeparator",									net.sf.aprstrack.unit.UByteSeparator.class },
		//{ "io.DownloadBytes",									net.sf.aprstrack.unit.UDownloadBytes.class },
		//{ "findu.FinduPacketBytes",								net.sf.aprstrack.unit.UFinduPacketBytes.class },
		//{ "is.AprsIsPacketFeed",								net.sf.aprstrack.unit.UAprsIsPacketFeed.class },
		//{ "is.AprsIsFeed",									net.sf.aprstrack.unit.UAprsIsFeed.class },
		////{ "findu.FinduRawRequest",								net.sf.aprstrack.unit.UFinduRawRequest.class },
		//{ "io.FixedFieldParser",								net.sf.aprstrack.unit.UFixedFieldParser.class },
		//{ "plcs.Place2K",									net.sf.aprstrack.unit.UPlace2K.class },
		//{ "aprs.Maidenhead",									net.sf.aprstrack.unit.UMaidenhead.class },
	};

	public static void main(String[] args) {
		test(TESTS);
	}

	private static final void test(Object[][] tests) {
		for (int idx = 0; idx < tests.length; idx++) {
			test((Class)tests[idx][1], (String)tests[idx][0]);
		}
	}

	private static final void test(Class aclass, String label) {
		TestSuite suite = new TestSuite(aclass);
		TestResult tresult = new TestResult();
		suite.run(tresult);
		summarizeSuite(label, tresult);
	}

  private static final void summarizeSuite(String title, TestResult tr) {
        System.out.println(title);
        System.out.println("\ttests conducted = " + tr.runCount());
        int errorcount = tr.errorCount();
        System.out.println("\terror count = " + errorcount);
        if (errorcount > 0) {
                reportErrors(tr.errors());
        }
        int failcount = tr.failureCount();
        System.out.println("\tfailure count = " + failcount);
        if (failcount > 0) {
                reportErrors(tr.failures());
        }

  }

  private static final void reportErrors(Enumeration errors) {
        while (errors.hasMoreElements()) {
                TestFailure tf = (TestFailure) errors.nextElement();
                System.out.print("\t\t");
                System.out.println(tf.toString());
        }
  }

}
